//
//  VC_CourseComment.m
//  yjw-winner
//
//  Created by 隆霁 on 2018/9/25.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_CourseComment.h"
#import "JudgeStarsView.h"


static const NSString *starsValueContext;
@interface VC_CourseComment ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet JudgeStarsView *starView;
@property (weak, nonatomic) IBOutlet UILabel *valueLabel;


@end

@implementation VC_CourseComment
- (instancetype)init {
    if (self = [super init]) {
        self = [[UIStoryboard storyboardWithName:@"CourseListStoryBoard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:NSStringFromClass([self class])];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.starView addObserver:self forKeyPath:@"stars" options:NSKeyValueObservingOptionNew context:&starsValueContext];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    if (context == &starsValueContext) {
        // stars
        [self setStarLabelTextWithStars:self.starView.stars];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc {
    [self.starView removeObserver:self forKeyPath:@"stars" context:&starsValueContext];
}

#pragma mark --mark 业务逻辑

/**
 根据stars 填写label文字

 @param stars stars
 */
- (void)setStarLabelTextWithStars:(CGFloat)stars {
    NSString *text = @"";
    if (stars == 0.5) {
        text = @"0.5分略感失望";
    }else if (stars == 1.0) {
        text = @"1.0分略感失望";
    }else if (stars == 1.5) {
        text = @"1.5分比较一般";
    }else if (stars == 2.0) {
        text = @"2.0分比较一般";
    }else if (stars == 2.5) {
        text = @"2.5分值得一听";
    }else if (stars == 3.0) {
        text = @"3.0分值得一听";
    }else if (stars == 3.5) {
        text = @"3.5分十分精彩";
    }else if (stars == 4.0) {
        text = @"4.0分十分精彩";
    }else if (stars == 4.5) {
        text = @"4.5分强烈推荐";
    }else if (stars == 5.0) {
        text = @"5.0分强烈推荐";
    }else {
        text = @"0分";
    }
    self.valueLabel.text = text;
}



#pragma mark --mark EVENT

/**
 提交评论

 @param sender sender
 */
- (IBAction)commitButtonClick:(UIButton *)sender {
    if (self.textView.text.length >= 10 && self.textView.text.length <= 300) {
        // 提交
        [MBProgressHUD showSuccess:@"提交评价"];
    }else {
        [MBProgressHUD showSuccess:@"评价文字至少需要10个字"];
    }
}


@end
